load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//pkg/sql/colexecop:EXECGEN.bzl", "eg_go_filegroup", "gen_eg_go_rules")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "colconv",
    srcs = [
        "batch.go",
        ":gen-exec",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/colconv",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/col/coldata",
        "//pkg/col/typeconv",  # keep
        "//pkg/sql/colexecerror",  # keep
        "//pkg/sql/execinfra/execreleasable",  # keep
        "//pkg/sql/rowenc",  # keep
        "//pkg/sql/sem/tree",  # keep
        "//pkg/sql/types",  # keep
        "//pkg/util/encoding",  # keep
        "//pkg/util/json",  # keep
        "//pkg/util/timeutil/pgdate",  # keep
        "//pkg/util/uuid",  # keep
        "@com_github_cockroachdb_errors//:errors",  # keep
        "@com_github_lib_pq//oid",  # keep
    ],
)

go_test(
    name = "colconv_test",
    srcs = ["batch_test.go"],
    embed = [":colconv"],
    deps = [
        "//pkg/col/coldata",
        "//pkg/sql/types",
        "//pkg/util/leaktest",
        "@com_github_stretchr_testify//require",
    ],
)

# Map between target name and relevant template.
targets = [
    ("datum_to_vec.eg.go", "datum_to_vec_tmpl.go"),
    ("vec_to_datum.eg.go", "vec_to_datum_tmpl.go"),
]

# Define a file group for all the .eg.go targets.
eg_go_filegroup(
    name = "gen-exec",
    targets = targets,
)

# Define gen rules for individual eg.go files.
gen_eg_go_rules(targets)

disallowed_imports_test(
    "colconv",
    ["//pkg/sql/execinfra"],
)
